package cn.edu.scau.disk.controller;

import cn.edu.scau.disk.exception.CommonException;
import cn.edu.scau.disk.pojo.User;
import cn.edu.scau.disk.service.TestService;
import cn.edu.scau.disk.utils.R;
import cn.edu.scau.disk.utils.Token;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("test")
@Validated
public class TestController {

    @Autowired
    TestService testService;

    @GetMapping
    public R testGet(@RequestHeader("token")String token, User user) throws CommonException {
        testService.login(user);
        return R.ok()
                .put("user",user)
                .put("token",token);
    }

    @PostMapping
    public R testError(@Valid User user) throws CommonException {
        throw new CommonException("error test");
    }

    @PutMapping
    @Token
    public R testToken(){
        return R.ok();

    }
}
